import React, { Component } from "react";

const Child2 = (props) => {
  return <div>child2组件 - {props.num}</div>;
};

class Child1 extends Component {
  state = {
    count: 10,
  };
  render() {
    console.log(this);
    return <div>child1组件 - {this.state.count}</div>;
  }
  componentDidMount() {
    this.props.onAbc(this.state.count);
  }
}

class App extends Component {
  state = {
    num: null,
  };

  fn = (c) => {
    console.log("fn", c);
    this.setState({
      num: c,
    });
  };

  render() {
    return (
      <>
        <h2>状态提升</h2>
        <Child1 onAbc={this.fn} />
        <Child2 num={this.state.num} />
      </>
    );
  }
}

export default App;
